#!/bin/bash
###编写人：2502全体
###编写日期：2025年4月30日
###版本功能：把业务系统的三张来源表的数据抽取到hive的ods层
###来源表：rdbms_cust_info、rdbms_org_info、rdbms_code_info
###落地表：不用提前创建落地表，会自动生成落地表
echo "开始编写配置参数"
j="jdbc:oracle:thin:@192.168.1.56:1521/ORCL"
u="scott"
p="123456"
t1="RDBMS_CUST_INFO"
t2="RDBMS_ORG_INFO"
t3="RDBMS_CODE_INFO"
db_1="ods02"
db_2="dw02"
db_3="dm02"
s_t="dw_cust_info" #dw层客户信息表的表名
s_t2="customer_order_summary" #dm层的指标汇总表
echo "首先把hive端的两张需要建表的表格进行创建"
echo "创建dw层客户基本信息表"
hive -e "create table if not exists ${db_2}.${s_t}(
cust_id   double,  
cust_name   string,    
org_id     double,      
code_id    double,      
amt   double,       
dt    string,       
phone   string,       
acctno    double,       
yg_no   double,
etl_time string
)
row format delimited fields terminated by ',';"
echo $?
echo "创建dm层指标汇总表"
hive -e "create table if not exists ${db_3}.${s_t2}(
org_name	string,				
sum_qk		decimal(22,6),				
sum_aqk		decimal(22,6),				
sum_ack		decimal(22,6),				
sum_ck		decimal(22,6),				
sum_dgzz	decimal(22,6),			
sum_dszz	decimal(22,6),				
sum_dzz		decimal(22,6),				
sum_lc		decimal(22,6),				
sum_dck		decimal(22,6),
etl_time string	
)row format delimited fields terminated by ',';"
echo $?
echo "开始编写sqoop语句进行数据的全量抽取"
echo "客户基表"
sqoop import \
--hive-import \
--connect ${j} \
--username ${u} \
--password ${p} \
--table ${t1} \
--hive-database ${db_1} \
--fields-terminated-by ',' -m 1
echo $?
echo "机构码表"
sqoop import \
--hive-import \
--connect ${j} \
--username ${u} \
--password ${p} \
--table ${t2} \
--hive-database ${db_1} \
--fields-terminated-by ',' -m 1
echo $?
echo "地址码表"
sqoop import \
--hive-import \
--connect ${j} \
--username ${u} \
--password ${p} \
--table ${t3} \
--hive-database ${db_1} \
--fields-terminated-by ',' -m 1
echo $?


